import { createRouter, createWebHistory } from 'vue-router'

// 引入一个个的路由组件
import home from '/src/views/home.vue'
import about from '/src/views/about.vue'
import service from '/src/views/service.vue'
import solution from '/src/views/solution.vue'
import platform from '/src/views/platform.vue'
import login from '/src/views/login.vue'
import register from '/src/views/register.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // 根路径重定向到home
    {
      path: '/',
      redirect: '/home'
    },
    {
      path:'/login',
      component:login
    },
    {
      path:'/register',
      component:register
    },
    {
      path:'/home',
      component:home
    },
    {
      path:'/about',
      component:about
    },
    {
      path:'/service',
      component:service
    },
    {
      path:'/solution',
      component:solution
    },
    {
      path:'/platform',
      component:platform
    },
  ],
  // 路由跳转时自动滚动到页面顶部
  scrollBehavior(to, from, savedPosition) {
    // 如果有保存的位置（例如浏览器后退），则返回到保存的位置
    if (savedPosition) {
      return savedPosition
    } else {
      // 否则滚动到页面顶部
      return { top: 0, behavior: 'smooth' }
    }
  }
})



export default router
